1
2 Imports System.Collections.Generic
3 Imports System.Text
4 Imports System.IO
5 Imports System.Security.Cryptography
6 Public Class Encryption
7 Public Shared Function InverseByBase(st As String, MoveBase As Integer) As String
8 Dim SB As New StringBuilder()
9 'st = ConvertToLetterDigit(st);
10 Dim c As Integer
11 Dim i As Integer = 0
12 While i < st.Length
13 If i + MoveBase > st.Length - 1 Then
14 c = st.Length - i
15 Else
16 c = MoveBase
17 End If
18 SB.Append(InverseString(st.Substring(i, c)))
19 i += MoveBase
20 End While
21 Return SB.ToString()
22 End Function
23
24 Public Shared Function InverseString(st As String) As String
25 Dim SB As New StringBuilder()
26 For i As Integer = st.Length - 1 To 0 Step -1
27 SB.Append(st(i))
28 Next
29 Return SB.ToString()
30 End Function
31
32 Public Shared Function ConvertToLetterDigit(st As String) As String
33 Dim SB As New StringBuilder()
34 For Each ch As Char In st
35 If Char.IsLetterOrDigit(ch) = False Then
36 SB.Append(Convert.ToInt16(ch).ToString())
37 Else
38 SB.Append(ch)
39 End If
40 Next
41 Return SB.ToString()
42 End Function
43
44 ''' <summary>
45 ''' moving all characters in string insert then into new index
46 ''' </summary>
47 ''' <param name="st">string to moving characters</param>
48 ''' <returns>moved characters string</returns>
49 Public Shared Function Boring(st As String) As String
50 Dim NewPlace As Integer
51 Dim ch As Char
52 For i As Integer = 0 To st.Length - 1
53 NewPlace = i * Convert.ToUInt16(st(i))
54 NewPlace = NewPlace Mod st.Length
55 ch = st(i)
56 st = st.Remove(i, 1)
57 st = st.Insert(NewPlace, ch.ToString())
58 Next
59 Return st
60 End Function
61
62 Public Shared Function MakePassword(st As String, Identifier As String) As String
63 If Identifier.Length <> 3 Then
64 Throw New ArgumentException("Identifier must be 3 character length")
65 End If
66
67 Dim num As Integer() = New Integer(2) {}
68 num(0) = Convert.ToInt32(Identifier(0).ToString(), 10)
69 num(1) = Convert.ToInt32(Identifier(1).ToString(), 10)
70 num(2) = Convert.ToInt32(Identifier(2).ToString(), 10)
71 st = Boring(st)
72 st = InverseByBase(st, num(0))
73 st = InverseByBase(st, num(1))
74 st = InverseByBase(st, num(2))
75
76 Dim SB As New StringBuilder()
77 For Each ch As Char In st
78 SB.Append(ChangeChar(ch, num))
79 Next
80 Return SB.ToString()
81 End Function
82
83 Private Shared Function ChangeChar(ch As Char, EnCode As Integer()) As Char
84 ch = Char.ToUpper(ch)
85 If ch >= "A"c AndAlso ch <= "H"c Then
86 Return Convert.ToChar(Convert.ToInt16(ch) + 2 * EnCode(0))
87 ElseIf ch >= "I"c AndAlso ch <= "P"c Then
88 Return Convert.ToChar(Convert.ToInt16(ch) - EnCode(2))
89 ElseIf ch >= "Q"c AndAlso ch <= "Z"c Then
90 Return Convert.ToChar(Convert.ToInt16(ch) - EnCode(1))
91 ElseIf ch >= "0"c AndAlso ch <= "4"c Then
92 Return Convert.ToChar(Convert.ToInt16(ch) + 5)
93 ElseIf ch >= "5"c AndAlso ch <= "9"c Then
94 Return Convert.ToChar(Convert.ToInt16(ch) - 5)
95 Else
96 Return "0"c
97 End If
98 End Function
99 End Class